home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / nn.zip / DATE_REG.C < prev    next >
C/C++ Source or Header  |  1989-06-28  |  1KB  |  75 lines

  1. /*
  2.  * produce input for nngoback
  3.  *
  4.  *    generates a regular expression for egrep that will
  5.  *    match the last N days, execute egrep with this pattern
  6.  *    and output a sequence of "group-name article" pairs
  7.  */
  8.  
  9. #include "config.h"
  10. #include <time.h>
  11.  
  12. #define DAYS    * 24 * 60 * 60
  13.  
  14. main(argc, argv)
  15. int argc;
  16. char **argv;
  17. {
  18.     time_t now, then;
  19.     struct tm *tm, *localtime();
  20.     int then_year, then_month, then_day;
  21.     int first;
  22.     
  23.     if (argc != 2) {
  24.     fprintf(stderr, "usage: nngoback1 <days>\n");
  25.     exit(1);
  26.     }
  27.  
  28.     time(&now);    
  29.  
  30.     then = now - (atoi(argv[1]) DAYS);
  31.     tm = localtime(&then);
  32.     then_year = tm->tm_year;
  33.     then_month = tm->tm_mon;
  34.     then_day = tm->tm_mday;
  35.     
  36.     tm = localtime(&now);
  37.  
  38.     printf("\t(");
  39.     
  40.     first = 0;
  41.     while (tm->tm_year > then_year) {
  42.     printf("%s%02d", first == 0 ? "../../(" : "|", tm->tm_year);
  43.     first = 1;
  44.  
  45.     tm->tm_year--;
  46.     tm->tm_mon = 11;
  47.     tm->tm_mday = 31;
  48.     }
  49.     if (first == 1) putchar(')');
  50.     
  51.     while (tm->tm_mon > then_month) {
  52.     printf(first == 0 ? "(" : first == 1 ? "|(" : "|");
  53.     first = 2;
  54.     printf("%02d", tm->tm_mon + 1);
  55.     tm->tm_mon --;
  56.     tm->tm_mday = 31;
  57.     }
  58.     if (first == 2) printf(")/../%02d", then_year);
  59.     
  60.     while (tm->tm_mday >= then_day) {
  61.     if (first != 0)
  62.         printf("|");
  63.     if (first != 3) 
  64.         printf("%02d/(", then_month + 1);
  65.     first = 3;
  66.     printf("%02d", tm->tm_mday);
  67.     tm->tm_mday--;
  68.     }
  69.     if (first == 3) printf(")/%02d", then_year);
  70.     
  71.     printf(")\n");
  72.     
  73.     exit(0);
  74. }
  75.